home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 7.0 KB | 179 lines | [TEXT/ttxt] |
- --<<<-
- --*******************************************************************************
- --* Demo for: MenuButton
- --* Required files: textmenu.sx
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*-----------------------------------------------------------------------------*
- --* Description: This script demonstrates how to create a hierarchical text
- --* menu.
- --* When you run "hiarcmen.sxt", you should see a window
- --* with a settings menu with the following menu structure:
- --*
- --* Settings - Reset
- --* - Color - Fill - Red
- --* - Green
- --* - Blue
- --* - Stroke - Red
- --* - Green
- --* - Blue
- --*
- --*******************************************************************************
-
- module TextMenuModule
- uses ScriptX
- end
-
- in module TextMenuModule
-
- --*=============================================================================*
- --* Load required files
- --*=============================================================================*
- -- Load MenuButton
- fileIn theScriptDir name:"textmenu.sx"
-
-
- --*=============================================================================*
- --* Define Demo
- --*=============================================================================*
- class Demo (Window)
- end
-
- --*=============================================================================*
- --* Method name: makeMenu
- --* Class: Demo
- --* Usage: makeMenu self
- --*-----------------------------------------------------------------------------*
- --* Description: Makes the menu and its submenus.
- --*=============================================================================*
- method makeMenu self {class Demo} ->
- (
- --*=========================================================================*
- --* Create the settings menu
- --* Note: the 'supermenu' keyword is 'undefined'
- --*=========================================================================*
- local settingsMenu := new MenuButton supermenu:undefined \
- label:"Settings" \
- width:60
-
- --*=========================================================================*
- --* Create the reset item under the settings menu
- --*=========================================================================*
- addmenuitem settingsMenu "Reset" self (authordata me -> \
- authordata.fill := authordata.stroke := blackBrush)
-
- --*=========================================================================*
- --* Create the color sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. settingsMenu
- --*=========================================================================*
- local colorMenu := new MenuButton supermenu:settingsMenu \
- label:"Color" \
- placement:@menuRight
-
- --*=========================================================================*
- --* Create the fill sub-sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. colorMenu
- --*=========================================================================*
- local fillMenu := new MenuButton supermenu:colorMenu \
- label:"Fill" \
- placement:@menuRight
-
- --*=========================================================================*
- --* Create the red, green and blue items under the fill menu
- --*=========================================================================*
- addmenuitem fillMenu "Red" self (authordata me -> \
- authordata.fill := (new Brush color:redColor))
- addmenuitem fillMenu "Green" self (authordata me -> \
- authordata.fill := (new Brush color:greenColor))
- addmenuitem fillMenu "Blue" self (authordata me -> \
- authordata.fill := (new Brush color:blueColor))
-
- --*=========================================================================*
- --* Create the stroke sub-sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. colorMenu
- --*=========================================================================*
- local strokeMenu := new MenuButton supermenu:colorMenu \
- label:"Stroke" \
- placement:@menuRight
-
- --*=========================================================================*
- --* Create the red, green and blue items under the fill menu
- --*=========================================================================*
- addmenuitem strokeMenu "Red" self (authordata me -> \
- authordata.stroke := (new Brush color:redColor))
- addmenuitem strokeMenu "Green" self (authordata me -> \
- authordata.stroke := (new Brush color:greenColor))
- addmenuitem strokeMenu "Blue" self (authordata me -> \
- authordata.stroke := (new Brush color:blueColor))
-
- return settingsMenu
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Demo
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates a 200x200 window.
- --*=============================================================================*
- method init self {class Demo} #rest args ->
- (
- -- Create a 200x200 window
- apply nextMethod self boundary:(new Rect x2:200 y2:200) \
- centered:true \
- fill:blackBrush \
- stroke:blackBrush \
- name:"Select from Menu" args
- return self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Demo
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Makes the menu and appends it to the demo window.
- --*=============================================================================*
- method afterInit self {class Demo} #rest args ->
- (
- --*=========================================================================*
- --* Create an actuator controller to control all the buttons in the demo
- --* window.
- --*=========================================================================*
- new ActuatorController space:self wholespace:true
-
- --*=========================================================================*
- --* Add menu to the demo window and display it
- --*=========================================================================*
- prepend self (makeMenu self)
- show self
-
- return self
- )
-
- --*=============================================================================*
- --* Create a title container
- --*=============================================================================*
- object tc (TitleContainer)
- dir : theScriptDir
- path : "textmenu.sxt"
- name : "Hierarchical Text Menu"
- end
-
- --*=============================================================================*
- --* Create demo
- --*=============================================================================*
- object win (Demo)
- title:tc
- end
-
- --*=============================================================================*
- --* Store module in the title container
- --*=============================================================================*
- append tc (getModule @TextMenuModule)
- tc.startUpAction := (tc -> load tc[1]
- show win)
- close tc
- -->>>